package models;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

/**
 * 基础模型
 * 
 * @author ultrafrog
 * @version 1.0, 2014-11-03
 * @since 1.0
 */
@MappedSuperclass
public class Model extends Identity {

	/** 创建用户 */
	@Column(name = "fk_creator")
	public String creator;
	
	/** 创建时间 */
	@Column(name = "dt_create_time")
	public Date createTime;
	
	/** 更新用户 */
	@Column(name = "fk_updater")
	public String updater;
	
	/** 更新时间 */
	@Column(name = "dt_update_time")
	public Date updateTime;
	
	/**
	 * 持久化前调用
	 */
	@PrePersist
	protected void onPrePersist() {
		creator = null;
		createTime = new Date();
		updater = creator;
		updateTime = createTime;
	}
	
	/**
	 * 更新前调用
	 */
	@PreUpdate
	protected void onPreUpdate() {
		updater = null;
		updateTime = new Date();
	}
}
